# note --------------------------------------------------------------------

# this figure is based on data from the 2014 chapel hill expert survey
# the complete dataset is available at https://www.chesdata.eu/

# import the pp dataset and plot the figure -------------------------------

figure_s1a <- read.csv("datasets/data_pp.csv") %>%
  filter(dataset == "ches") %>%
  mutate(party = factor(party, levels = c("akp", "chp", "mhp", "hdp"),
                        labels = c("AKP", "CHP", "MHP", "HDP"))) %>%
  pivot_wider(names_from = measure, values_from = value) %>%
  ggplot(aes(x = party, y = lrgen)) +
  geom_errorbar(aes(ymin = lrgen - lrgen_sd, ymax = lrgen + lrgen_sd),
                width = 0.1, linetype = "dashed", size = 0.8) +
  geom_point(size = 2) +
  theme_light() +
  theme(axis.line = element_line(colour = "black", size = 0.25),
        panel.grid.major = element_line(colour = "grey95", size = 0.25),
        panel.grid.minor = element_line(colour = "grey95", size = 0.125),
        panel.border = element_rect(fill = NA, colour = "grey95", 
                                      size = 0.25),
        axis.text = element_text(size = 14), 
        axis.title = element_text(size = 14),
        legend.position = "none") +
  labs(x = NULL, y = "Left-right positions in 2014\n")

# display the figure ------------------------------------------------------

print(figure_s1a)

# save the figure ---------------------------------------------------------

ggsave(plot = figure_s1a, filename = "figures/figure_s1a.pdf", dpi = 1000,
       width = 8.5, height = 6, units = "in")